package com.zhuizikejithreeig.cn.threeigkeji.loginfo;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.zhuizikejithreeig.cn.threeigkeji.BasicActivity;
import com.zhuizikejithreeig.cn.threeigkeji.CompontApplayCation;
import com.zhuizikejithreeig.cn.threeigkeji.MainActivity;
import com.zhuizikejithreeig.cn.threeigkeji.R;
import com.zhuizikejithreeig.cn.utils.ToastMake;

import kr.co.namee.permissiongen.PermissionFail;
import kr.co.namee.permissiongen.PermissionGen;
import kr.co.namee.permissiongen.PermissionSuccess;

public class ChoceOtherActivity extends BasicActivity implements View.OnClickListener {
    private static final int READSDK = 105;
    private ImageView mImage1;
    private ImageView mImage2;
    private ImageView mImage3;
    private Button    mName8;
    private ImageView mImagemian;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView_V(R.layout.activity_choce_other);
        showBody();
        mImage1 = (ImageView) findViewById(R.id.image1);
        mImage2 = (ImageView) findViewById(R.id.image2);
        mImage3 = (ImageView) findViewById(R.id.image3);
        mImagemian = (ImageView) findViewById(R.id.imagemian);
        mName8 = (Button) findViewById(R.id.name8);

        mImage1.setOnClickListener(this);
        mImagemian.setOnClickListener(this);
        mImage2.setOnClickListener(this);
        mImage3.setOnClickListener(this);
        mName8.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image1:
                CompontApplayCation.postion = "2";
                mImage1.setImageDrawable(getResources().getDrawable(R.mipmap.select_qian));
                mImage2.setImageDrawable(getResources().getDrawable(R.mipmap.touminghou));
                mImage3.setImageDrawable(getResources().getDrawable(R.mipmap.touminghou));
                break;
            case R.id.image2:
                CompontApplayCation.postion = "3";
                mImage2.setImageDrawable(getResources().getDrawable(R.mipmap.hou_left));
                mImage1.setImageDrawable(getResources().getDrawable(R.mipmap.seat));
                mImage3.setImageDrawable(getResources().getDrawable(R.mipmap.touminghou));
                break;
            case R.id.image3:
                CompontApplayCation.postion = "4";
                mImage3.setImageDrawable(getResources().getDrawable(R.mipmap.hou_right));
                mImage1.setImageDrawable(getResources().getDrawable(R.mipmap.seat));
                mImage2.setImageDrawable(getResources().getDrawable(R.mipmap.touminghou));
                break;
            //开始扫码
            case R.id.name8:
                if (ContextCompat.checkSelfPermission(ChoceOtherActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    ToastMake.showToast(getResources().getString(R.string.string69));
                    hasReadPermission();

                }else {
                    startActivity(new Intent(ChoceOtherActivity.this, BundingSetActivity.class));
                    finish();
                }
                break;

            case R.id.imagemian:
                ToastMake.showToast("主驾无需扫码");
                break;
        }
    }
    private void hasReadPermission() {
        PermissionGen.with(ChoceOtherActivity.this)
                .addRequestCode(READSDK)
                .permissions(
                        Manifest.permission.CAMERA
                )
                .request();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
        PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @PermissionSuccess(requestCode = READSDK)
    public void requestPhotoSuccess() {
        //成功之后的处理
        //.......
        startActivity(new Intent(ChoceOtherActivity.this, BundingSetActivity.class));
        finish();
    }

    @PermissionFail(requestCode = READSDK)
    public void requestPhotoFail() {
        //失败之后的处理，我一般是跳到设置界面

        boolean showRequestPermission = ActivityCompat.shouldShowRequestPermissionRationale(ChoceOtherActivity.this, Manifest.permission.CAMERA);
        if (showRequestPermission ) {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.parse("package:" + getPackageName()));
            startActivity(intent);
        }


    }
}

